﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using blackhouse.BlackApart.Business.Apartments;
using System.Web.UI;
using blackhouse.BlackApart.Business;

namespace blackhouse.BlackApart.Web {
	public class CalendarDay {

		#region Properties

		public int Day { get; set; }
		public int NextDay { get; set; }
		public int DayOfWeek { get; set; }
		public int Week { get; set; }
		public DateTime AssocDate { get; set; }
		public CalendarDayType Type { get; set; }
		public string UrlToReservation { get; set; }

		#endregion

		#region Constructors

		public CalendarDay() { }

		public CalendarDay(DateTime date, int week, int plDayOfWeek) {
			this.Day = date.Day;
			this.NextDay = this.Day + 1;
			if (date.AddDays(1).Month != date.Month)
				this.NextDay = 1;
			this.DayOfWeek = plDayOfWeek;
			this.Week = week;
			this.AssocDate = date;
			this.Type = CalendarDayType.Free;
			if (this.AssocDate.Date < DateTime.Now.Date)
				this.Type = CalendarDayType.Overdate;

		}

		#endregion

		#region Methods

		public void SetUrlToReservation(int groupId) {
			Factory factory = Factory.Instance();
			IApartmentGroup group = null;
			if (groupId > 0)
				group = factory.GetApartmentGroup(groupId);

			string name = HttpContext.GetGlobalResourceObject("Aparts", "findFreeApartments").ToString();

			if (group != null && group.Id == groupId)
				name = group.Name.CleanStringForUrl();

			this.UrlToReservation = UrlUtils.GetReservationUrl(factory.GetPreFolderEvaluation(), this.AssocDate, this.AssocDate.AddDays(1), 1, groupId, name);
		}

		#endregion
	}

	public enum CalendarDayType {

		Free,
		Overdate,
		Busy

	}

}